<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="设备id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceId">
              <a-input v-model="model.deviceId" placeholder="请输入设备id"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小风速，m/s" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="minwspeed">
              <a-input v-model="model.minwspeed" placeholder="请输入最小风速，m/s"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平均风速，m/s " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avlwspeed">
              <a-input v-model="model.avlwspeed" placeholder="请输入平均风速，m/s "  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最大风速，m/s " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maxwspeed">
              <a-input v-model="model.maxwspeed" placeholder="请输入最大风速，m/s "  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最小风向，度 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="minwdir">
              <a-input v-model="model.minwdir" placeholder="请输入最小风向，度 "  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平均风向，度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="avlwdir">
              <a-input v-model="model.avlwdir" placeholder="请输入平均风向，度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最大风向，度 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="maxwdir">
              <a-input v-model="model.maxwdir" placeholder="请输入最大风向，度 "  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="雨量，单位mm " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rains">
              <a-input v-model="model.rains" placeholder="请输入雨量，单位mm "  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="气压，单位hPa" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="airkpas">
              <a-input v-model="model.airkpas" placeholder="请输入气压，单位hPa"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="辐射量，单位 W/M2" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="radiation">
              <a-input v-model="model.radiation" placeholder="请输入辐射量，单位 W/M2"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="紫外线强度等级，单位UVI" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ultraviolet">
              <a-input v-model="model.ultraviolet" placeholder="请输入紫外线强度等级，单位UVI"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="单位dB" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="noises">
              <a-input v-model="model.noises" placeholder="请输入单位dB"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="pm25值, 0.1 ug/m3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pm25s">
              <a-input v-model="model.pm25s" placeholder="请输入pm25值, 0.1 ug/m3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="pm10值, 0.1 ug/m3" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pm1s">
              <a-input v-model="model.pm1s" placeholder="请输入pm10值, 0.1 ug/m3"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="测量温度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mtemps">
              <a-input v-model="model.mtemps" placeholder="请输入测量温度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="测量湿度，单位 %RH" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="mhumis">
              <a-input v-model="model.mhumis" placeholder="请输入测量湿度，单位 %RH"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间戳" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tmstamp">
              <j-date placeholder="请选择时间戳" v-model="model.tmstamp"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'WeatherDataForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           tmstamp: [
              { required: true, message: '请输入时间戳!'},
           ],
        },
        url: {
          add: "/corp/weatherData/add",
          edit: "/corp/weatherData/edit",
          queryById: "/corp/weatherData/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>